package com.example.mylifecycles;

import android.content.Context;
import android.os.SystemClock;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.Chronometer;

import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;

public class MyChronometer extends Chronometer implements LifecycleObserver {
    private Long elapseTime;
    public MyChronometer(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
    private void pauseMeter(){
        elapseTime = SystemClock.elapsedRealtime()-getBase();
        Log.i("TAG", "pauseMeter: ");
       stop();

    }
    @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
    private void resumeMete(){
        Log.i("TAG", "resumeMete: ");
//        setBase(SystemClock.elapsedRealtime()-elapseTime);
       start();
    }
}
